#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>

#include "led.h"

struct leddev*
        leddev_construct(
                void)
{
	int gpionum[6] = {54, 55, 56, 45, 44, 62};
	struct leddev *dev;
	int i;
		
	dev = calloc(1, sizeof(struct leddev));
	if (NULL == dev) {
		perror("calloc leddev");
		return NULL;
	}

	for (i = 0; i < 6; i++) { 
		dev->gpiodev[i] = gpiodev_construct(gpionum[i]);
		if (NULL == dev->gpiodev[i]) {
			printf("gpiodev_construct %d error\n", i);
			return NULL;
		}
		gpiodev_export(dev->gpiodev[i]);
		gpiodev_setdir(dev->gpiodev[i], 0);
		gpiodev_setval(dev->gpiodev[i], 0);
	}
	return dev;
}


void
        leddev_deconstruct(
        	struct leddev *dev)
{
	int i;

	for (i = 0; i < 6; i++)
		gpiodev_deconstruct(dev->gpiodev[i]);
	free(dev);
}


void
        leddev_on(
                struct leddev *dev, int num)
{

	gpiodev_setval(dev->gpiodev[num], 0);
}

void
        leddev_off(
                struct leddev *dev, int num)
{
	gpiodev_setval(dev->gpiodev[num], 1);
}















